#include "wndmanager.h"
#include <QtGui>
#include "mainmenu.h"
#include "loadprogramwnd.h"
#include "programwnd.h"
#include "measmenu.h"
#include "detailwnd.h"
#include "filesavewnd.h"

namespace WndManager {

const char *kDefaultFont = "Fixedsys";

// Active Window, only one window exists at one time to reduce memory use
QWidget *activeWnd = NULL;


void AdjustWndStyle(QWidget *widget)
{
	widget->setFont(QFont(kDefaultFont, kGeneralFontSize));

#ifdef __arm__	// micro2440 environment
	
	QFont font = widget->font();
	font.setPixelSize(font.pointSize() * 4 / 3);
	widget->setFont(font);

	widget->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
	widget->showMaximized();

#else	// pc environment

	widget->setFixedSize(kMaxWndWidth, kMaxWndHeight);

#endif	// __arm__
}


void gotoWnd(WndNo wndNo, int item_index)
{
	QWidget *oldWnd = activeWnd;
	switch(wndNo){
		case kWndMainMenu:
			activeWnd = new MainMenu;
		break;
		case kWndLoadProgramWnd:
			activeWnd = new LoadProgramWnd;
		break;
		case kWndProgramWnd:
			qDebug() << "enter program wnd";	// without these 2 qDebug(),
			activeWnd = new ProgramWnd;			// there is always a segment
		break;									// fault... FIXME:
		case kWndDetailWnd:
			activeWnd = new DetailWnd(item_index);
		break;
		case kWndSaveFileWnd:
			qDebug() << "enter file save wnd";
			activeWnd = new FileSaveWnd;
		break;
		case kWndMeasMenu:
			activeWnd = new MeasMenu;
		break;
		default:
		break;
	}
	AdjustWndStyle(activeWnd);
	activeWnd->show();

	if(oldWnd != NULL){
		delete oldWnd;
	}
}

} // namespace WndManager
